import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../res/r.dart';
import 'load_image_widget.dart';

class CustomLoadingWidget extends StatefulWidget {
  const CustomLoadingWidget({super.key, required this.msg});

  final String msg;

  @override
  State<CustomLoadingWidget> createState() => _CustomLoadingWidgetState();
}

class _CustomLoadingWidgetState extends State<CustomLoadingWidget> with TickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(milliseconds: 1000),
      vsync: this,
    );
    _controller.forward();
    _controller.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        _controller.reset();
        _controller.forward();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 100.w,
      height: 70.w,
      decoration: BoxDecoration(
        color: Color(0xB2000000),
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Center(
              child: RotationTransition(
                alignment: Alignment.center,
                turns: _controller,
                child: LoadImageWidget(
                  R.icLoading,
                  width: 20.w,
                  height: 20.w,
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 8.w),
              child: Text(
                widget.msg,
                style: TextStyle(fontSize: 13.sp, color: Colors.white),
              ),
            ),
          ]),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
